package com.example.foobar.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.foobar.business.service.ImsPzGuanhuaiTrackService;
import com.example.foobar.dao.service.ImsPzGuanhuaiTrackDaoService;
import com.example.foobar.dto.DABaseDTO;
import com.example.foobar.entity.DaRetentionRates;
import com.example.foobar.entity.ImsPzGuanhuaiTrack;
import com.example.foobar.mapper.ImsPzGuanhuaiTrackMapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  服务实现类
 *
 * @author 郑英奔
 * @since 2021-05-31
 */
@Slf4j
@Service
public class ImsPzGuanhuaiTrackServiceImpl implements ImsPzGuanhuaiTrackService {

    @Autowired
    private ImsPzGuanhuaiTrackDaoService imsPzGuanhuaiTrackDaoService;

    public boolean saveImsPzGuanhuaiTrack(ImsPzGuanhuaiTrack imsPzGuanhuaiTrack) throws Exception {
        return imsPzGuanhuaiTrackDaoService.save(imsPzGuanhuaiTrack);
    }

    public boolean updateImsPzGuanhuaiTrack(ImsPzGuanhuaiTrack imsPzGuanhuaiTrack) throws Exception {
        return imsPzGuanhuaiTrackDaoService.updateById(imsPzGuanhuaiTrack);
    }

    public boolean deleteImsPzGuanhuaiTrack(Long id) throws Exception {
        return imsPzGuanhuaiTrackDaoService.removeById(id);
    }

    @Override
    public List<ImsPzGuanhuaiTrack> list(QueryWrapper<ImsPzGuanhuaiTrack> wrapper) {
        return imsPzGuanhuaiTrackDaoService.list(wrapper);
    }

    @Override
    public ImsPzGuanhuaiTrack getById(Long id) {
        return imsPzGuanhuaiTrackDaoService.getById(id);
    }

    @Override
    public Integer selectCount(LambdaQueryWrapper<ImsPzGuanhuaiTrack> imsPzGuanhuaiTrackLambdaQueryWrapper) throws Exception {
        return imsPzGuanhuaiTrackDaoService.selectCount(imsPzGuanhuaiTrackLambdaQueryWrapper);
    }

    @Override
    public List<DABaseDTO> getActiveDataByOfficialAccountIdAndDataRange(String uniacid, Date baseDate, Date startDate, Date endDate, List<String> messageTypeList) {
        String messageTypes = "'" + String.join("','", messageTypeList) + "'" ;
        Map<String, Object> params = new HashMap<>();
        params.put("uniacid" ,uniacid);
        params.put("baseDate" ,baseDate);
        params.put("startDate" ,startDate);
        params.put("endDate" ,endDate);
        params.put("messageTypes" ,messageTypes);

        return imsPzGuanhuaiTrackDaoService.getActiveDataByOfficialAccountIdAndDataRange(params);
    }

    @Override
    public int getSubscribeCount(String uniacid, Date date) {
        Map<String, Object> params = new HashMap<>();
        params.put("uniacid", uniacid);
        params.put("date", date);
        return imsPzGuanhuaiTrackDaoService.getSubscribeCount(params);
    }

    @Override
    public int getUnsubscribeCount(String uniacid, Date date) {
        Map<String, Object> params = new HashMap<>();
        params.put("uniacid", uniacid);
        params.put("date", date);
        return imsPzGuanhuaiTrackDaoService.getUnsubscribeCount(params);
    }

    @Override
    public Date minDateInDb() {
        return imsPzGuanhuaiTrackDaoService.minDateInDb();
    }


}
